package cn.sumpu.app.wlcity.web.mvc.login;


import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.sumpu.app.wlcity.domain.User;

@Controller
public class LoginController {
	
	@RequestMapping(value = "/toLogin.htm")
	public String toLogin(HttpServletRequest request) {
		return "cms/login";
	}
	
	@RequestMapping(value = "/login.htm")
	public String login(String name,String password,HttpServletRequest request,HttpServletResponse response) throws IOException {
		if("admin".equals(name) && "admin".equals(password)){
			User user = new User();
			user.setName(name);
			user.setPassword(password);
			request.getSession().setAttribute("user", user);
			response.sendRedirect("/main.cms");
			return null;
		}else{
			request.setAttribute("error", "登录名密码不正确！");
			return "cms/login";	
		}
		
	}
	
	@RequestMapping(value = "/main.cms")
	public String main(HttpServletRequest request) {
		return "cms/main";
	}
}
